﻿package plugin.union.game
{
    import com.core.*;
    import com.greensock.*;
    import com.sh.game.display.*;
    import com.sh.game.global.*;
    import flash.display.*;
    import flash.events.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import morn.core.managers.*;
    import plugin.union.*;
    import uiresource.union.*;

    public class UnionTotemGame extends UnionTotemUI implements IPage
    {
        private var curSelect:int = 0;
        private var effect:XMLMovieClip;
        private var attStr:String = "";
        private var tween:TweenMax;
        private var needCost:int = 0;

        public function UnionTotemGame()
        {
            this.initEvent();
            App.mloader3.loadAssets([{url:Config.getUrl("assets/images/speff/union.swf"), type:ResLoader.SWF, size:100, priority:1}, {url:Config.getUrl("assets/images/speff/toten.xml"), type:ResLoader.TXT, size:50, priority:1}], new Handler(this.onComplete));
            return;
        }// end function

        private function onComplete() : void
        {
            var _loc_1:* = ResLoader.getResLoaded(Config.getUrl("assets/images/speff/toten.xml"));
            this.effect = new XMLMovieClip("png.union.toten", new XML(_loc_1));
            this.addChild(this.effect);
            this.effect.play();
            this.effect.x = -280;
            this.effect.y = -40;
            this.effect.toolTip = this.attStr;
            this.effect.addEventListener(MouseEvent.ROLL_OVER, this.doMouse);
            return;
        }// end function

        protected function doMouse(event:MouseEvent) : void
        {
            switch(event.type)
            {
                case MouseEvent.ROLL_OUT:
                {
                    this.effect.addEventListener(MouseEvent.ROLL_OVER, this.doMouse);
                    this.effect.removeEventListener(MouseEvent.ROLL_OUT, this.doMouse);
                    if (this.tween)
                    {
                        this.tween.kill();
                        this.tween = null;
                    }
                    this.effect.filters = null;
                    break;
                }
                case MouseEvent.ROLL_OVER:
                {
                    this.effect.removeEventListener(MouseEvent.ROLL_OVER, this.doMouse);
                    this.effect.addEventListener(MouseEvent.ROLL_OUT, this.doMouse);
                    if (this.tween)
                    {
                        this.tween.kill();
                        this.tween = null;
                    }
                    this.tween = TweenMax.to(this.effect, 1, {glowFilter:{color:16763904, alpha:1, blurX:10, blurY:10}, yoyo:true, repeat:int.MAX_VALUE});
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function initEvent() : void
        {
            list_attribute.selectHandler = new Handler(this.doSelect);
            btn_qd.clickHandler = new Handler(this.doQd);
            txt_way.addEventListener(MouseEvent.CLICK, this.doClick);
            txt_way.toolTip = "通过装备捐献仓库获得贡献度";
            return;
        }// end function

        protected function doClick(event:MouseEvent) : void
        {
            ModelProxy.change("union", "todonation", null);
            return;
        }// end function

        private function doSelect(param1:int) : void
        {
            if (this.curSelect == param1)
            {
                return;
            }
            this.curSelect = param1;
            this.refresh();
            return;
        }// end function

        public function effectCom(param1:int, param2:int) : void
        {
            clip_select.y = param1;
            clip_select.x = param2;
            TweenLite.to(clip_select, 0.3, {alpha:1});
            return;
        }// end function

        public function refresh() : void
        {
            var _loc_8:int = 0;
            var _loc_9:int = 0;
            var _loc_10:int = 0;
            var _loc_11:Array = null;
            var _loc_12:int = 0;
            clip_select.blendMode = BlendMode.ADD;
            clip_select.y = int(this.curSelect / 4) * 118 + 150;
            clip_select.x = this.curSelect % 4 * 116 + 265;
            var _loc_1:* = ModelProxy.getValue("data", "unionTotem");
            var _loc_2:Array = [];
            var _loc_3:int = 0;
            var _loc_4:* = ModelProxy.getValue("data", "unionInfo");
            var _loc_5:* = UserData.getUserData("name");
            txt_curNum.text = "当前贡献度:" + UserData.getBagData("contribution");
            if (_loc_1)
            {
                _loc_3 = int(_loc_1[0]);
                _loc_9 = 0;
                while (_loc_9 < _loc_2.length)
                {
                    
                    _loc_10 = _loc_1[_loc_8];
                    _loc_1[_loc_8] = _loc_10;
                    if (_loc_3 > _loc_10)
                    {
                        _loc_3 = _loc_10;
                    }
                    _loc_9++;
                }
            }
            this.attStr = "<font color = \'#e19f21\'>图腾等级：</font><font color = \'#53b436\'>" + _loc_3 + "</font>\n\n";
            this.attStr = this.attStr + "<font color = \'#e19f21\'>属性加成:</font>\n";
            var _loc_6:Array = [0, 0, 0, 0, 0, 0, 0, 0];
            var _loc_7:* = ConfigDictionary.data.unionTotem;
            _loc_8 = 0;
            while (_loc_8 < 8)
            {
                
                _loc_11 = _loc_7[_loc_8];
                _loc_12 = _loc_1[_loc_8];
                _loc_2[_loc_8] = {curAtt:_loc_11[_loc_12], nextAtt:_loc_11[(_loc_12 + 1)]};
                if (_loc_12 == 0)
                {
                }
                else
                {
                    _loc_6[_loc_8] = _loc_11[_loc_12].value;
                }
                _loc_8++;
            }
            list_attribute.array = _loc_2;
            list_attribute.renderHandler = new Handler(this.attributeRender);
            this.attStr = this.attStr + ("<font color=\'#ffe4c7\'>攻    击：</font><font color = \'#53b436\'>" + _loc_6[0] + "-" + _loc_6[1] + "</font>\n");
            this.attStr = this.attStr + ("<font color=\'#ffe4c7\'>物理防御：</font><font color = \'#53b436\'>" + _loc_6[2] + "-" + _loc_6[3] + "</font>\n");
            this.attStr = this.attStr + ("<font color=\'#ffe4c7\'>魔法防御：</font><font color = \'#53b436\'>" + _loc_6[4] + "-" + _loc_6[5] + "</font>\n");
            this.attStr = this.attStr + ("<font color=\'#ffe4c7\'>生    命：</font><font color = \'#53b436\'>" + _loc_6[6] / 100 + "%</font>\n");
            this.attStr = this.attStr + ("<font color=\'#ffe4c7\'>魔    法：</font><font color = \'#53b436\'>" + _loc_6[7] / 100 + "%</font>");
            if (this.effect)
            {
                this.effect.toolTip = this.attStr;
            }
            return;
        }// end function

        private function attributeRender(param1:Component, param2:int) : void
        {
            var _loc_3:Array = null;
            var _loc_4:Object = null;
            var _loc_5:Image = null;
            var _loc_6:Label = null;
            if (param2 < list_attribute.length)
            {
                _loc_4 = list_attribute.array[param2];
                _loc_5 = param1.getChildByName("icon") as Image;
                _loc_5.url = "png.NewUnion.icon" + param2;
                _loc_5.smoothing = true;
                _loc_6 = param1.getChildByName("count") as Label;
                if (_loc_4.curAtt)
                {
                    _loc_6.text = this.getType(_loc_4.curAtt.type) + ":" + (_loc_4.curAtt.type >= 6 ? (_loc_4.curAtt.value / 100 + "%") : (_loc_4.curAtt.value));
                    if (_loc_4.nextAtt)
                    {
                        _loc_3 = _loc_4.nextAtt.cost.split("#");
                        param1.toolTip = "当前等级:" + _loc_4.curAtt.level + "\n" + this.getType(_loc_4.curAtt.type) + ":+" + (_loc_4.curAtt.type >= 6 ? (_loc_4.curAtt.value / 100 + "%") : (_loc_4.curAtt.value)) + "\n下一级别:" + _loc_4.nextAtt.level + "\n" + this.getType(_loc_4.nextAtt.type) + ":+" + (_loc_4.curAtt.type >= 6 ? (_loc_4.nextAtt.value / 100 + "%") : (_loc_4.nextAtt.value));
                        if (param2 == this.curSelect)
                        {
                            txt_cost.text = "本次需要消耗：" + _loc_3[1] + "贡献度";
                            this.needCost = _loc_3[1];
                        }
                    }
                    else
                    {
                        txt_cost.text = "当前等级已满";
                        param1.toolTip = "下一级别:\n等级已满";
                    }
                }
                else
                {
                    _loc_3 = _loc_4.nextAtt.cost.split("#");
                    _loc_6.text = this.getType(_loc_4.nextAtt.type) + ":" + 0 + (_loc_4.nextAtt.type >= 6 ? ("%") : (""));
                    if (param2 == this.curSelect)
                    {
                        txt_cost.text = "本次需要消耗：" + _loc_3[1] + "贡献度";
                        this.needCost = _loc_3[1];
                    }
                    param1.toolTip = "下一级别:" + _loc_4.nextAtt.level + "\n" + this.getType(_loc_4.nextAtt.type) + ":+" + (_loc_4.nextAtt.type >= 6 ? (_loc_4.nextAtt.value / 100 + "%") : (_loc_4.nextAtt.value));
                }
            }
            return;
        }// end function

        public function doQd() : void
        {
            var _loc_3:int = 0;
            var _loc_1:* = ModelProxy.getValue("data", "unionInfo");
            var _loc_2:* = ModelProxy.getValue("data", "unionTotem");
            if (int(_loc_2[this.curSelect]) < _loc_1.unionLevel)
            {
                _loc_3 = UserData.getBagData("contribution");
                if (this.needCost > 0)
                {
                    if (_loc_3 >= this.needCost)
                    {
                        UnionSender._33upTotem(this.curSelect);
                    }
                    else
                    {
                        WarningManager.show(3);
                    }
                }
                else
                {
                    WarningManager.show(4);
                }
            }
            else
            {
                WarningManager.show(2);
            }
            return;
        }// end function

        private function getType(param1:int) : String
        {
            var _loc_2:String = "";
            switch(param1)
            {
                case 0:
                {
                    _loc_2 = "攻击下限";
                    break;
                }
                case 1:
                {
                    _loc_2 = "攻击上限";
                    break;
                }
                case 2:
                {
                    _loc_2 = "物防下限";
                    break;
                }
                case 3:
                {
                    _loc_2 = "物防上限";
                    break;
                }
                case 4:
                {
                    _loc_2 = "魔防下限";
                    break;
                }
                case 5:
                {
                    _loc_2 = "魔防上限";
                    break;
                }
                case 6:
                {
                    _loc_2 = "生命";
                    break;
                }
                case 7:
                {
                    _loc_2 = "魔法";
                    break;
                }
                default:
                {
                    break;
                }
            }
            return _loc_2;
        }// end function

        public function update(param1:int, param2:Object) : void
        {
            return;
        }// end function

    }
}
